package com.eims.ball.info.adapter;

import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.contans.view.FenxiJibenVo;
import com.contans.view.FenxiJifenVo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import bls.juejin.cn.R;

public class FanxiJibenJifenListAdapter extends BaseAdapter {
	private Context context;
	private FenxiJibenVo fenxiJibenVo;
	private ArrayList<FenxiJifenVo> fenxiJifenVos;

	public FanxiJibenJifenListAdapter(Context context, FenxiJibenVo fenxiJibenVo) {
		super();
		this.context = context;
		this.fenxiJibenVo = fenxiJibenVo;
		fenxiJifenVos = fenxiJibenVo.getJifenVo();
	}

	@Override
	public int getCount() {
		if (fenxiJifenVos != null) {
			return fenxiJifenVos.size();
		}

		return 0;
	}

	@Override
	public Object getItem(int position) {

		return position;
	}

	@Override
	public long getItemId(int position) {

		return position;
	}

	@Override
	public View getView(final int position, View view, ViewGroup parent) {
		ViewHolder holder;
		// 判断View是否为空
		final String[] numStr=fenxiJifenVos.get(position).getAll().split(",");
		if (view == null) {
			holder = new ViewHolder();

			view = LayoutInflater.from(context).inflate(R.layout.fenxi_jiben_jifen_listview_item, null);

			holder.tv_paiming = (TextView) view.findViewById(R.id.tv_paiming);
			holder.tv_name = (TextView) view.findViewById(R.id.tv_name);
			holder.tv_shenfu = (TextView) view.findViewById(R.id.tv_shengfu);
			holder.tv_jinshi = (TextView) view.findViewById(R.id.tv_jinshi);

			holder.tvJifen = (TextView) view.findViewById(R.id.tv_jifen);

			view.setTag(holder);
		} else {
			holder = (ViewHolder) view.getTag();
		}

		holder.tv_paiming.setText(fenxiJifenVos.get(position).getRank());
		holder.tv_name.setText(fenxiJifenVos.get(position).getTeamname());
		holder.tv_shenfu.setText(numStr[1]+"/"+numStr[2]+"/"+numStr[3]);
		holder.tv_jinshi.setText(numStr[4]+"/"+numStr[5]);
		holder.tvJifen.setText(fenxiJifenVos.get(position).getPoints());
		
		
		return view;
	}

	public boolean isMobileNO(String mobiles) {
		Pattern p = Pattern.compile("1[0-9]{10}");
		Matcher m = p.matcher(mobiles);
		return m.matches();
	}

	static class ViewHolder {
		TextView tv_paiming, tv_name, tv_shenfu, tv_jinshi, tvJifen;
	}

	public String formateRate(String rateStr) {
		if (rateStr.indexOf(".") != -1) {

			int num = 0;
			num = rateStr.indexOf(".");

			String dianAfter = rateStr.substring(0, num + 1);
			String afterData = rateStr.replace(dianAfter, "");
			if (afterData.length() < 2) {
				afterData = afterData + "0";
			} else {
				afterData = afterData;
			}
			return rateStr.substring(0, num) + "." + afterData.substring(0, 2);
		} else {
			if (rateStr == "1") {
				return "100";
			} else {
				return rateStr;
			}
		}
	}

}
